/*
 *    Copyright 2022 jacky4631 shen ji email:121659050@qq.com
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package com.dataoke.shoppingguide.app773026;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;

/**
 * 配置类
 * @author: shen ji
 * @date: 2022/3/15
 * @email: 121659050@qq.com
 * @wechat: jacky4631
 */
public class SharedPreferenceUtil {
    protected SharedPreferences mSp;
    protected SharedPreferences.Editor mEditor;

    @SuppressLint("CommitPrefEdits")
     SharedPreferenceUtil(Context context, String name) {
        this.mSp = context.getSharedPreferences(name, Context.MODE_PRIVATE);
        this.mEditor = mSp.edit();
    }

    public String getString(String key, String defaultStr) {
        return mSp.getString(key, defaultStr);
    }

    protected boolean getBoolean(String key, boolean defaultBoolean) {
        return mSp.getBoolean(key, defaultBoolean);
    }

    public int getInt(String key, int defaultInt) {
        return mSp.getInt(key, defaultInt);
    }

    public long getLong(String key, long defaultLong) {
        return mSp.getLong(key, defaultLong);
    }

    public float getFloat(String key, float defaultFloat) {
        return mSp.getFloat(key, defaultFloat);
    }

    public void put(String key, String value) {
        if (key == null || value == null) {
            return;
        }
        mEditor.putString(key, value);
        mEditor.commit();
    }

    public void put(String key, boolean value) {
        mEditor.putBoolean(key, value);
        mEditor.commit();
    }

    public void put(String key, int value) {
        mEditor.putInt(key, value);
        mEditor.commit();
    }

    public void put(String key, double value) {
        put(key, String.valueOf(value));
    }

    public void put(String key, float value) {
        put(key, String.valueOf(value));
    }

    public void put(String key, long value){
        mEditor.putLong(key,value);
        mEditor.commit();
    }
}
